<?php

class Ext_Utils_SyncFormWithSession {

    static public function sync( $controller, $session, $form, $defaults = array() ) {
        $params = $controller->getRequest()->getParams();
        
        $className = get_class( $controller ) . get_class( $form );
        

        // Seteo los defaults.
        if ( is_array( $session->$className ) ) {
            $form->setDefaults( $session->$className );
        } else {
            $form->setDefaults( $defaults );
        }
        
        // Seteo los parametros a partir del request.
        $form->setDefaults( $params );
        
        // Guardo en la session
        $session->$className = $form->getValues();
    }
}
